﻿/*************************************************
 * 
 *  框架执行Ajax请求框架通用js
 * 
 *  create by ternence
 * 
 *  create datetime at 2017-03-20
 *  
 *  西安佳卓信息科技有限公司 ©2017
 * 
 * ***********************************************/

/**
 * 请求Ajax
 * 返回Json类型字符串
 * JSON.stringify({ 'foo': 'foovalue', 'bar': 'barvalue' }),  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
 */
function ZorPostSimpleData(url, postData, callBack) {
    $.ajax({
        type: "POST",
        url: url,                         
        contentType: "application/json",  
        dataType: "json",                 
        data: postData,                   
        success: function (jsonResult) {
            callBack(jsonResult)
        }
    });
}

/* 
 * 请求Ajax 带返回值
 * 返回String类型字符串
 */
function ZorPostStringData(url, postData, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: postData,
        cache: false,
        async: false,
        success: function (data) {
            callBack(data);
        },
        //error: function (data) {
        //    alert("error:" + data + "url:" + url);
        //    Loading(false);
        //}
    });
}

/**
 * 请求Ajax 带返回值
 * 返回List<string>类型
 * JSON.stringify({ "BuIds": ["1", "2", "3"] }),
 */
function ZorpostListString(url, postData, callBack) {
    $.ajax({
        type: "POST",
        url: url,
        contentType: "application/json",
        dataType: "json",
        data: postData,                     
        success: function (jsonResult) {
            callBack(jsonResult);
        }
    });
}


/**
 * 请求Ajax 带返回值
 * 返回 <T>
 * JSON.stringify({"Employees": { "firstName": "Bill", "lastName": "Gates" }})
 */
function ZorpostEmployees(url, postData, callBack) {
    $.ajax({
        type: "POST",
        url: url,
        contentType: "application/json",
        dataType: "json",
        data: postData,
        success: function (jsonResult) {
            callBack(jsonResult);
        }
    });
}

/**
 * 请求Ajax 带返回值
 * 返回 List<T>
 * JSON.stringify({"Employees": [{ "firstName": "Bill", "lastName": "Gates" },{ "firstName": "George", "lastName": "Bush" },{ "firstName": "Thomas", "lastName": "Carter" }]})
 */
function ZorpostListEmployees(url, postData, callBack) {
    $.ajax({
        type: "POST",
        url: "/Service/Employees",
        contentType: "application/json",
        dataType: "json",
        data: postData,
        success: function (jsonResult) {
            callBack(jsonResult);
        }
    });
}


